<script>
    // 父类
    class Person{
        // 构造器函数
        constructor(name, a){
            this.name = name;
            this.age = a;
            console.log('父类构造器函数');
        }
        // 添加方法
        eat(){
            console.log(`${ this.name }吃饭了`);
        }
    }
    // 创建Student子类：name age idCard，study方法
    class Student extends Person{
        // 子类没有constructor构造器函数时，该语法正确的，自动执行父类的构造器函数
        
        // 子类如果有constructor函数，必须在第一行执行super()
        constructor(uname, age, idCard){
            super(uname, age);  // 调用父类构造器函数   传参
            this.idCard = idCard;
        }
        // 添加方法
        study(){
            console.log(`${ this.name }学习了`);
        }
    }
    let s1 = new Student('小红', 15, 12345);
    console.log(s1);
    console.log(s1.name);
    s1.eat();


    // Must call super constructor in derived class before accessing 'this' or returning from derived constructor
</script>